package com.ruoyi.project.applet.service.impl;

import java.util.List;

import com.ruoyi.project.applet.domain.Wallet;
import com.ruoyi.project.applet.mapper.WalletMapper;
import com.ruoyi.project.applet.service.IWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 钱包Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-10
 */
@Service
public class WalletServiceImpl implements IWalletService
{
    @Autowired
    private WalletMapper walletMapper;

    /**
     * 查询钱包
     * 
     * @param id 钱包ID
     * @return 钱包
     */
    @Override
    public Wallet selectWalletById(Long id)
    {
        return walletMapper.selectWalletById(id);
    }

    /**
     * 查询钱包列表
     * 
     * @param wallet 钱包
     * @return 钱包
     */
    @Override
    public List<Wallet> selectWalletList(Wallet wallet)
    {
        return walletMapper.selectWalletList(wallet);
    }

    /**
     * 新增钱包
     * 
     * @param wallet 钱包
     * @return 结果
     */
    @Override
    public int insertWallet(Wallet wallet)
    {
        return walletMapper.insertWallet(wallet);
    }

    /**
     * 修改钱包
     * 
     * @param wallet 钱包
     * @return 结果
     */
    @Override
    public int updateWallet(Wallet wallet)
    {
        return walletMapper.updateWallet(wallet);
    }

    /**
     * 批量删除钱包
     * 
     * @param ids 需要删除的钱包ID
     * @return 结果
     */
    @Override
    public int deleteWalletByIds(Long[] ids)
    {
        return walletMapper.deleteWalletByIds(ids);
    }

    /**
     * 删除钱包信息
     * 
     * @param id 钱包ID
     * @return 结果
     */
    @Override
    public int deleteWalletById(Long id)
    {
        return walletMapper.deleteWalletById(id);
    }

    @Override
    public Wallet getWalletMoney(String openId) {
        Wallet walletMoney = walletMapper.getWalletMoney(openId);
        if (walletMoney == null) {
            walletMoney = new Wallet();
            walletMoney.setMoney("0");
            walletMoney.setUserId(openId);
            walletMapper.insertWallet(walletMoney);
        }
        return walletMoney;
    }
}
